package org.hxyjs.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Salesagent;
import org.hxyjs.entity.Salesagent;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.SalesagentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/salesagentController")
public class SalesagentController {
	@Resource
	SalesagentService salesagentService;
	@RequiresPermissions("salesagent:getAll")
	@RequestMapping("/getAllSalesagent")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Salesagent> getAllSalesagent() throws Exception {
    	System.out.println("查询全部销售代理");
		return salesagentService.getAllSalesagents();
    }

	@RequestMapping("/deleteSalesagentBySano/{aano}")
	@ResponseBody
    public DTO<Salesagent> deleteSalesagentBySano(@PathVariable("aano") String aano) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(aano+"删除销售代理");
    	return salesagentService.deleteSalesagentBySano(aano);
    }

	@RequestMapping("/updateSalesagentBySano")
	@ResponseBody
	public DTO<Salesagent> updateSalesagentBySano(@RequestBody Salesagent salesagent) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改销售代理");
		return salesagentService.updateSalesagentBySano(salesagent);
	}


	@RequestMapping("/addSalesagent")
	@ResponseBody
	public DTO<Salesagent> addSalesagent(@RequestBody Salesagent salesagent) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加销售代理");
		System.out.println(salesagent);
 		return salesagentService.addSalesagent(salesagent);
	}
	
	@RequestMapping("/getSalesagentByPage")
	@ResponseBody
	public DTO<Salesagent> getSalesagentByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return salesagentService.getSalesagentByPage(pageInfo);
	}

}